// otherTap/pages/snapShotDetail/snapShotDetail.js
const db = wx.cloud.database();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    eventType:null,//事件类型
    location: "", //定位的位置
    time:0,//时间
    name:"",
    phone:"",
    id:null,
    reply:null,
    imgs:[],
    headImg:"",
    nickname:"",
    descri:"",
    scrollTop:"comment"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.comment){
      setTimeout(()=>{
        this.setData({
          scrollTop:"comment",
        })
      },1200)
    }
    this.setData({
      id:options._id
    })
    this.getData();
  },
   //到底时让评论拉取更多数据
   onReachBottom(){
    this.selectComponent('.comment').onReachBottom()
  },

  getData(){
    db.collection('snapShot').doc(this.data.id).get().then(res=>{
      console.log(res.data);
      this.setData({
        nickname:res.data.nickname,
        headImg:res.data.headImg,
        eventType:res.data.eventType,
        time:res.data.time,
        location:res.data.location,
        phone:res.data.phone,
        name:res.data.name,
        descri:res.data.descri,
        imgs:res.data.photoUrl,
        reply:res.data.reply
      })
    })
  },
//放大预览图片
handleImagePreview(e) {
  const idx = e.target.dataset.idx
  const imgs = this.data.imgs
  wx.previewImage({
    current: imgs[idx], //当前预览的图片
    urls: imgs, //所有要预览的图片
  })
},
  //到底时让评论拉取更多数据
  onReachBottom(){
    this.selectComponent('.comment').onReachBottom()
  },
  onShareAppMessage() {},
  onShareTimeline() {},
  onAddToFavorites() {},
})